//
//  FunyController.swift
//  StudyDY
//
//  Created by yinchangming on 2018/7/11.
//  Copyright © 2018年 yinchangming. All rights reserved.
//

import UIKit
let kNormalID="kNormalID"
class FunyController: BaseViewController {
    private lazy var collection={ () -> UICollectionView in
        let layout = UICollectionViewFlowLayout()
        layout.itemSize=CGSize(width: kItemWidth, height: kItemHeight)
        layout.minimumLineSpacing=0
        layout.minimumInteritemSpacing=kItemMargin
        layout.sectionInset=UIEdgeInsets(top: 0, left: kItemMargin, bottom: 0, right: kItemMargin)
        let conView=UICollectionView(frame: self.view.bounds, collectionViewLayout: layout)
        conView.dataSource=self
        conView.register(UINib(nibName: "CollectionNormalCell", bundle: nil), forCellWithReuseIdentifier: kNormalID)
        conView.contentInset=UIEdgeInsets(top: kItemMargin, left: 0, bottom: 0, right: 0)
        conView.backgroundColor=UIColor.white
        conView.autoresizingMask=[.flexibleWidth,.flexibleHeight]
        return conView
    }()
    lazy var funyVm=FunyViewMode()
    override func viewDidLoad() {
      contentView=collection
        updateUI()
          super.viewDidLoad()
    }
}
extension FunyController{
    func updateUI(){
        view.addSubview(collection)
        funyVm.requsetData {
            self.collection.reloadData()
            self.finshRequst()
        }
    }
}
extension FunyController :UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return  self.funyVm.rooms.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell=collectionView.dequeueReusableCell(withReuseIdentifier: kNormalID, for: indexPath) as! CollectionNormalCell
        cell.room = self.funyVm.rooms[indexPath.item]
        return cell
    }
    
    
}
